package LeetCode._01_树;

public class _700_二叉搜索树中的搜索 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public TreeNode searchBST(TreeNode root, int val) {
        if(root == null) return null;
        if(root.val > val){ //大于去左子树
            return searchBST(root.left,val);
        }
        if(root.val<val){ //小于去右子树
            return searchBST(root.right,val);
        }
        return root; //相等就是找到的情况，直接返回即可
    }
}
